BlazorExport.BaseExt.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using FastReport.SVG;
  2. using FastReport.Utils;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Text;
  9. using Microsoft.AspNetCore.Components;
  10. namespace FastReport.Web.Blazor.Export
  11. {
  12. public partial class BlazorExport
  13. {
  14. /// <inheritdoc/>
  15. protected override void ExportBand(BandBase band)
  16. {
  17. ExportBandLayers(band);
  18. }
  19. private static bool HasExtendedExport(ReportComponentBase obj)
  20. {
  21. return obj is SVGObject;
  22. }
  23. #region svg
  24. private string? GetLayerSVG(SVGObject svg, out float Width, out float Height)
  25. {
  26. Width = 0;
  27. Height = 0;
  28. if (svg != null)
  29. {
  30. if (pictures)
  31. {
  32. Width = svg.Width == 0 ? svg.Border.LeftLine.Width : svg.Width;
  33. Height = svg.Height == 0 ? svg.Border.TopLine.Width : svg.Height;
  34. if (Math.Abs(Width) * Zoom < 1 && Zoom > 0)
  35. Width = 1 / Zoom;
  36. if (Math.Abs(Height) * Zoom < 1 && Zoom > 0)
  37. Height = 1 / Zoom;
  38. MemoryStream svgStream = new MemoryStream();
  39. if (svg.Grayscale)
  40. svg.SVGGrayscale.Write(svgStream);
  41. else
  42. svg.SvgDocument.Write(svgStream);
  43. svgStream.Position = 0;
  44. string result = HTMLGetImage(d.CurrentPage, Crypter.ComputeHash(svgStream), svgStream, true);
  45. return result;
  46. }
  47. }
  48. return null;
  49. }
  50. private void LayerSVG(in IRenderContext context, SVGObject obj)
  51. {
  52. if (pictures)
  53. {
  54. float Width, Height;
  55. string? svg = GetLayerSVG(obj, out Width, out Height);
  56. StringBuilder addstyle = new StringBuilder(64);
  57. addstyle.Append(defaultStyle);
  58. addstyle.Append(" background: url('").Append(svg).Append("') center center no-repeat !important;-webkit-print-color-adjust:exact;");
  59. if (obj.Angle != 0)
  60. {
  61. addstyle.Append($"transform: rotate({obj.Angle}deg);");
  62. }
  63. float x = obj.Width > 0 ? obj.AbsLeft : (obj.AbsLeft + obj.Width);
  64. float y = obj.Height > 0 ? obj.AbsTop : (obj.AbsTop + obj.Height);
  65. Layer(context, obj, x, y, obj.Width, obj.Height, null, null, addstyle);
  66. // cleanup SVG
  67. obj.Dispose();
  68. }
  69. }
  70. #endregion
  71. }
  72. }