StandardPrintController.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. using System;
  11. namespace System.Drawing.Printing {
  12. /// <summary>
  13. /// Summary description for StandardPrintController.
  14. /// </summary>
  15. public class StandardPrintController : PrintController {
  16. private int page;
  17. private Image image;
  18. public StandardPrintController() {
  19. }
  20. [MonoTODO("StandardPrintController.OnEndPage")]
  21. public override void OnEndPage(PrintDocument document, PrintPageEventArgs e){
  22. //TODO: print current page
  23. // - image to print is this.image
  24. // - page settings are in e.PageSettings
  25. // - printer settings are in document.PrinterSettings
  26. // - don't forget to use document.OriginAtMargins (only if .NET 1.1)
  27. // actually, "print" == "save to a file"
  28. try
  29. {
  30. string fileName = document.DocumentName + " " + page.ToString("D4") + ".jpg";
  31. Console.WriteLine("StandardPrintController: Print page \"{0}\"", fileName);
  32. image.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  33. }
  34. catch (Exception) {}
  35. if (e.Graphics != null)
  36. e.Graphics.Dispose();
  37. }
  38. [MonoTODO("StandardPrintController.OnStartPrint")]
  39. public override void OnStartPrint(PrintDocument document, PrintEventArgs e){
  40. page = 0;
  41. }
  42. //[MonoTODO("StandardPrintController.OnEndPrint")]
  43. //public override void OnEndPrint(PrintDocument document, PrintEventArgs e){
  44. // throw new NotImplementedException ();
  45. //}
  46. [MonoTODO("StandardPrintController.OnStartPage")]
  47. public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e){
  48. //FIXME: I'm not sure of what I'm doing
  49. // I don't know what size to give to image
  50. // and why I have to clear it
  51. page++;
  52. // returns a new (empty) graphics
  53. image = new Bitmap(e.MarginBounds.Width, e.MarginBounds.Height);
  54. Graphics g = Graphics.FromImage(image);
  55. g.Clear(Color.White);
  56. return g;
  57. }
  58. }
  59. }