DefaultPrintController.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using FastReport.Utils;
  2. using System;
  3. using System.Collections;
  4. using System.Drawing;
  5. using System.Drawing.Printing;
  6. namespace FastReport.Print
  7. {
  8. internal class DefaultPrintController : PrintControllerBase
  9. {
  10. public override void QueryPageSettings(object sender, QueryPageSettingsEventArgs e)
  11. {
  12. Page = GetNextPage();
  13. if (Page != null)
  14. {
  15. SetPaperSize(Page, e);
  16. e.PageSettings.Landscape = Page.Landscape;
  17. SetPaperSource(Page, e);
  18. Duplex duplex = Page.Duplex;
  19. if (duplex != Duplex.Default)
  20. e.PageSettings.PrinterSettings.Duplex = duplex;
  21. }
  22. }
  23. public override void PrintPage(object sender, PrintPageEventArgs e)
  24. {
  25. StartPage(e);
  26. Graphics g = e.Graphics;
  27. IGraphics gr = GdiGraphics.FromGraphics(g);
  28. FRPaintEventArgs paintArgs;
  29. if (Config.IsRunningOnMono)
  30. {
  31. // Point is the only right thing to use in mono. Pixel unit produces weird layout
  32. g.PageUnit = GraphicsUnit.Point;
  33. g.ResetTransform();
  34. g.TranslateTransform(-e.PageSettings.HardMarginX / 100f * 72f, -e.PageSettings.HardMarginY / 100f * 72f);
  35. // workaround different pango/cairo rendering behavior
  36. if (DrawUtils.GetMonoRendering(gr) == MonoRendering.Pango)
  37. {
  38. g.ScaleTransform(72f / 96f, 72f / 96f);
  39. paintArgs = new FRPaintEventArgs(gr, 1, 1, Report.GraphicCache);
  40. }
  41. else
  42. {
  43. paintArgs = new FRPaintEventArgs(gr, 72f / 96f, 72f / 96f, Report.GraphicCache);
  44. }
  45. }
  46. else
  47. {
  48. g.PageUnit = GraphicsUnit.Pixel;
  49. g.TranslateTransform(-e.PageSettings.HardMarginX / 100f * g.DpiX, -e.PageSettings.HardMarginY / 100f * g.DpiY);
  50. paintArgs = new FRPaintEventArgs(gr, g.DpiX / 96, g.DpiY / 96, Report.GraphicCache);
  51. }
  52. #if Demo || Academic
  53. Page.Watermark.Text = "";
  54. #endif
  55. Page.Print(paintArgs);
  56. #if Demo
  57. using (Watermark trialWatermark = new Watermark())
  58. {
  59. trialWatermark.Text = typeof(Duplex).Name[0].ToString() + typeof(Exception).Name[0].ToString() +
  60. typeof(Margins).Name[0].ToString() + typeof(Object).Name[0].ToString() + " " +
  61. typeof(ValueType).Name[0].ToString() + typeof(Exception).Name[0].ToString() +
  62. typeof(Rectangle).Name[0].ToString() + typeof(ShapeKind).Name[0].ToString() +
  63. typeof(ICloneable).Name[0].ToString() + typeof(Object).Name[0].ToString() +
  64. typeof(NonSerializedAttribute).Name[0].ToString();
  65. trialWatermark.DrawText(paintArgs, new RectangleF(0, 0,
  66. Page.PaperWidth * Units.Millimeters, Page.PaperHeight * Units.Millimeters), Report, true);
  67. }
  68. #endif
  69. #if Academic
  70. using (Watermark trialWatermark = new Watermark())
  71. {
  72. trialWatermark.Text = typeof(Array).Name[0].ToString() + typeof(Char).Name[0].ToString() +
  73. typeof(Array).Name[0].ToString() + typeof(DateTime).Name[0].ToString() +
  74. typeof(Enum).Name[0].ToString() + typeof(Margins).Name[0].ToString() +
  75. typeof(IEnumerable).Name[0].ToString() + typeof(Char).Name[0].ToString() +
  76. " " +
  77. typeof(LineObject).Name[0].ToString() + typeof(IEnumerable).Name[0].ToString() +
  78. typeof(Char).Name[0].ToString() + typeof(Enum).Name[0].ToString() +
  79. typeof(Nullable).Name[0].ToString() + typeof(ShapeObject).Name[0].ToString() +
  80. typeof(Enum).Name[0].ToString();
  81. trialWatermark.DrawText(paintArgs, new RectangleF(0, 0,
  82. Page.PaperWidth * Units.Millimeters, Page.PaperHeight * Units.Millimeters), Report, true);
  83. }
  84. #endif
  85. Page.Dispose();
  86. FinishPage(e);
  87. e.HasMorePages = HasMorePages();
  88. }
  89. public DefaultPrintController(Report report, PrintDocument doc, int curPage) : base(report, doc, curPage)
  90. {
  91. }
  92. }
  93. }