HTMLExport.BaseExt.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #if DOTNET_4
  2. using FastReport.SVG;
  3. #endif
  4. using FastReport.Utils;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Globalization;
  9. using System.IO;
  10. using FastReport.AdvMatrix;
  11. using System.Text;
  12. namespace FastReport.Export.Html
  13. {
  14. public partial class HTMLExport
  15. {
  16. private void ExportHTMLPageBegin(object data)
  17. {
  18. HTMLData d = (HTMLData)data;
  19. if (layers)
  20. ExportHTMLPageLayeredBegin(d);
  21. else
  22. ExportHTMLPageTabledBegin(d);
  23. }
  24. private void ExportHTMLPageEnd(object data)
  25. {
  26. HTMLData d = (HTMLData)data;
  27. if (layers)
  28. ExportHTMLPageLayeredEnd(d);
  29. else
  30. ExportHTMLPageTabledEnd(d);
  31. }
  32. private string GetHrefAdvMatrixButton(ReportComponentBase obj, string href)
  33. {
  34. if (obj is MatrixButton)
  35. {
  36. MatrixButton matrixButton = obj as MatrixButton;
  37. string url = String.Format("{0},{1},{2}",
  38. EncodeURL(matrixButton.Name), // object name for security reasons
  39. CurPage,
  40. matrixButton.Index);
  41. string onClick = String.Format(OnClickTemplate, ReportID, "advmatrix_click", url);
  42. href = String.Format("<a onclick=\"{0}\">", onClick);
  43. }
  44. return href;
  45. }
  46. private void SetExportableAdvMatrix(Base c)
  47. {
  48. if (c is MatrixButton)
  49. {
  50. MatrixButton matrixButton = c as MatrixButton;
  51. matrixButton.Exportable = true;
  52. }
  53. }
  54. /// <inheritdoc/>
  55. protected override void ExportBand(BandBase band)
  56. {
  57. if (ExportMode == ExportType.Export)
  58. base.ExportBand(band);
  59. else
  60. band.UpdateWidth();
  61. //
  62. if (Layers)
  63. ExportBandLayers(band);
  64. else
  65. ExportBandTable(band);
  66. }
  67. private bool HasExtendedExport(ReportComponentBase obj)
  68. {
  69. #if DOTNET_4
  70. return obj is SVGObject;
  71. #else
  72. return false;
  73. #endif
  74. }
  75. private void ExtendExport(FastString Page, ReportComponentBase obj, FastString text)
  76. {
  77. #if DOTNET_4
  78. if (obj is SVGObject)
  79. LayerSVG(htmlPage, obj as SVGObject, null);
  80. #endif
  81. }
  82. #if DOTNET_4
  83. #region svg
  84. private string GetLayerSVG(SVGObject svg, out float Width, out float Height)
  85. {
  86. Width = 0;
  87. Height = 0;
  88. if (svg != null)
  89. {
  90. if (pictures)
  91. {
  92. Width = svg.Width == 0 ? svg.Border.LeftLine.Width : svg.Width;
  93. Height = svg.Height == 0 ? svg.Border.TopLine.Width : svg.Height;
  94. if (Math.Abs(Width) * Zoom < 1 && Zoom > 0)
  95. Width = 1 / Zoom;
  96. if (Math.Abs(Height) * Zoom < 1 && Zoom > 0)
  97. Height = 1 / Zoom;
  98. MemoryStream svgStream = new MemoryStream();
  99. if (svg.Grayscale)
  100. svg.SVGGrayscale.Write(svgStream);
  101. else
  102. svg.SvgDocument.Write(svgStream);
  103. svgStream.Position = 0;
  104. string result = HTMLGetImage(0, 0, 0, Crypter.ComputeHash(svgStream), true, null, svgStream, true);
  105. return result;
  106. }
  107. }
  108. return null;
  109. }
  110. private void LayerSVG(FastString Page, SVGObject obj, FastString text)
  111. {
  112. if (!pictures)
  113. return;
  114. float Width, Height;
  115. string svg = GetLayerSVG(obj, out Width, out Height);
  116. FastString addstyle = new FastString(64);
  117. addstyle.Append("position:absolute;");
  118. addstyle.Append(" background: url('").Append(svg).Append("') center center no-repeat !important;-webkit-print-color-adjust:exact;");
  119. if (obj.Angle != 0)
  120. {
  121. addstyle.Append($"transform: rotate({obj.Angle}deg);");
  122. }
  123. float x = obj.Width > 0 ? obj.AbsLeft : (obj.AbsLeft + obj.Width);
  124. float y = obj.Height > 0 ? hPos + obj.AbsTop : (hPos + obj.AbsTop + obj.Height);
  125. Layer(Page, obj, x, y, obj.Width, obj.Height, text, null, addstyle);
  126. // cleanup SVG
  127. obj.Dispose();
  128. }
  129. #endregion
  130. #endif
  131. }
  132. }