StandardPrintController.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // System.Drawing.StandardPrintController.cs
  3. //
  4. // Author:
  5. // Dennis Hayes ([email protected])
  6. // Herve Poussineau ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc
  9. //
  10. //
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System;
  33. namespace System.Drawing.Printing
  34. {
  35. public class StandardPrintController : PrintController
  36. {
  37. private int page;
  38. private Image image;
  39. public StandardPrintController()
  40. {
  41. }
  42. [MonoTODO("StandardPrintController.OnEndPage")]
  43. public override void OnEndPage(PrintDocument document, PrintPageEventArgs e)
  44. {
  45. //TODO: print current page
  46. // - image to print is this.image
  47. // - page settings are in e.PageSettings
  48. // - printer settings are in document.PrinterSettings
  49. // - don't forget to use document.OriginAtMargins (only if .NET 1.1)
  50. // actually, "print" == "save to a file"
  51. try
  52. {
  53. string fileName = document.DocumentName + " " + page.ToString("D4") + ".jpg";
  54. Console.WriteLine("StandardPrintController: Print page \"{0}\"", fileName);
  55. image.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  56. }
  57. catch (Exception) {}
  58. if (e.Graphics != null)
  59. e.Graphics.Dispose();
  60. }
  61. [MonoTODO("StandardPrintController.OnStartPrint")]
  62. public override void OnStartPrint(PrintDocument document, PrintEventArgs e){
  63. page = 0;
  64. }
  65. [MonoTODO("StandardPrintController.OnEndPrint")]
  66. public override void OnEndPrint(PrintDocument document, PrintEventArgs e){
  67. return;
  68. }
  69. [MonoTODO("StandardPrintController.OnStartPage")]
  70. public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
  71. {
  72. //FIXME: I'm not sure of what I'm doing
  73. // I don't know what size to give to image
  74. // and why I have to clear it
  75. page++;
  76. // returns a new (empty) graphics
  77. image = new Bitmap(e.MarginBounds.Width, e.MarginBounds.Height);
  78. Graphics g = Graphics.FromImage(image);
  79. g.Clear(Color.White);
  80. return g;
  81. }
  82. }
  83. }