DefaultPrintController.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Drawing.Printing;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using FastReport.Utils;
  6. using System.Drawing;
  7. namespace FastReport.Print
  8. {
  9. internal class DefaultPrintController : PrintControllerBase
  10. {
  11. public override void QueryPageSettings(object sender, QueryPageSettingsEventArgs e)
  12. {
  13. Page = GetNextPage();
  14. if (Page != null)
  15. {
  16. SetPaperSize(Page, e);
  17. e.PageSettings.Landscape = Page.Landscape;
  18. SetPaperSource(Page, e);
  19. Duplex duplex = Page.Duplex;
  20. if (duplex != Duplex.Default)
  21. e.PageSettings.PrinterSettings.Duplex = duplex;
  22. }
  23. }
  24. public override void PrintPage(object sender, PrintPageEventArgs e)
  25. {
  26. StartPage(e);
  27. Graphics g = e.Graphics;
  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(g) == MonoRendering.Pango)
  37. {
  38. g.ScaleTransform(72f / 96f, 72f / 96f);
  39. paintArgs = new FRPaintEventArgs(g, 1, 1, Report.GraphicCache);
  40. }
  41. else
  42. {
  43. paintArgs = new FRPaintEventArgs(g, 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(g, g.DpiX / 96, g.DpiY / 96, Report.GraphicCache);
  51. }
  52. Page.Print(paintArgs);
  53. Page.Dispose();
  54. FinishPage(e);
  55. e.HasMorePages = HasMorePages();
  56. }
  57. public DefaultPrintController(Report report, PrintDocument doc, int curPage) : base(report, doc, curPage)
  58. {
  59. }
  60. }
  61. }