BarcodeObject.BaseExt.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using FastReport.Utils;
  5. namespace FastReport.Barcode
  6. {
  7. public partial class BarcodeObject
  8. {
  9. #if DOTNET_4
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. public override bool IsHaveToConvert(object sender)
  14. {
  15. if (AsBitmap) return false;
  16. if (
  17. (sender is Export.Html.HTMLExport) && ((sender as Export.Html.HTMLExport).EnableVectorObjects && (sender as Export.Html.HTMLExport).Layers) ||
  18. (sender is Export.Pdf.PDFExport) && !((sender as Export.Pdf.PDFExport).SvgAsPicture)
  19. )
  20. return true;
  21. return base.IsHaveToConvert(sender);
  22. }
  23. /// <summary>
  24. ///
  25. /// </summary>
  26. public override IEnumerable<Base> GetConvertedObjects()
  27. {
  28. SVG.SVGObject svgObject = new SVG.SVGObject();
  29. svgObject.SetReport(Report);
  30. svgObject.Assign(this);
  31. svgObject.SetParentCore(this.Parent);
  32. svgObject.Left = Left;
  33. svgObject.Top = Top;
  34. svgObject.Padding = Padding;
  35. if (svgObject.Width == 0)
  36. svgObject.Width = 1;
  37. if (svgObject.Height == 0)
  38. svgObject.Height = 1;
  39. using (XmlDocument document = new XmlDocument())
  40. {
  41. using (SvgGraphics g = new SvgGraphics(document))
  42. {
  43. bool error = false;
  44. string errorText = "";
  45. if (String.IsNullOrEmpty(Text))
  46. {
  47. error = true;
  48. errorText = NoDataText;
  49. }
  50. else
  51. try
  52. {
  53. UpdateAutoSize();
  54. }
  55. catch (Exception ex)
  56. {
  57. error = true;
  58. errorText = ex.Message;
  59. }
  60. g.ViewPort = new RectangleF(0, 0, Width, Height);
  61. if (!error)
  62. barcode.DrawBarcode(g, new RectangleF(0, 0, Width, Height));
  63. else
  64. {
  65. g.DrawString(errorText, DrawUtils.DefaultReportFont, Brushes.Red,
  66. new RectangleF(0, 0, Width, Height));
  67. }
  68. }
  69. svgObject.SetSVGByContent(document.ToString());
  70. }
  71. // Fill for HTML & Pdf
  72. if (this.Fill != null && !this.Fill.IsTransparent)
  73. {
  74. TextObject fill = new TextObject();
  75. fill.Fill = this.Fill.Clone();
  76. fill.Left = this.Left;
  77. fill.Top = this.Top;
  78. fill.Width = this.Width;
  79. fill.Height = this.Height;
  80. fill.Parent = this.Parent;
  81. //fill.Font = null;
  82. yield return fill;
  83. }
  84. yield return svgObject;
  85. }
  86. #endif
  87. }
  88. }