ReportEngine.Rich.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using FastReport.Table;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq.Expressions;
  5. namespace FastReport.Engine
  6. {
  7. partial class ReportEngine
  8. {
  9. private void InitializePages()
  10. {
  11. for (int i = 0; i < Report.Pages.Count; i++)
  12. {
  13. ReportPage page = Report.Pages[i] as ReportPage;
  14. if (page != null)
  15. {
  16. PreparedPages.AddSourcePage(page);
  17. }
  18. }
  19. }
  20. /// <summary>
  21. /// Translate RichObject to series of ReportComponentBase objects
  22. /// </summary>
  23. /// <param name="rich"></param>
  24. internal float Translate_Rich(RichObject rich)
  25. {
  26. BandBase parentBand = rich.Parent as BandBase;
  27. float height = 0;
  28. bool isRich = rich.Text.StartsWith(@"{\rtf");
  29. if (rich.localVisibleStorage && rich.ConvertRichText)
  30. {
  31. height = rich.Convert2ReportObjects();
  32. }
  33. return height;
  34. }
  35. private void TranslateTableObject(TableBase table)
  36. {
  37. foreach (Base obj in table.AllObjects)
  38. {
  39. if (obj is RichObject)
  40. {
  41. RichObject rich = obj as RichObject;
  42. if (rich.Visible && rich.ConvertRichText)
  43. {
  44. float height = rich.Convert2ReportObjects();
  45. TableCell cell = rich.Parent as TableCell;
  46. foreach (ComponentBase trnslated_ojbect in rich.TransltedObjects)
  47. {
  48. trnslated_ojbect.Parent = cell;
  49. }
  50. rich.Visible = false;
  51. }
  52. }
  53. }
  54. }
  55. /// <summary>
  56. /// This code splits RichObject to report objects
  57. /// </summary>
  58. /// <param name="parentBand"></param>
  59. public void TranslateObjects(BandBase parentBand)
  60. {
  61. int originalObjectsCount = parentBand.Objects.Count;
  62. float shift = 0;
  63. for (int i = 0; i < originalObjectsCount; i++)
  64. {
  65. ComponentBase obj = parentBand.Objects[i];
  66. obj.Top += shift;
  67. if (obj is RichObject)
  68. {
  69. bool useVisibleExpression = !String.IsNullOrEmpty(obj.VisibleExpression);
  70. RichObject rich = obj as RichObject;
  71. if (rich.ConvertRichText)
  72. {
  73. if(useVisibleExpression)
  74. {
  75. obj.Visible = (bool) Report.Calc(Code.CodeUtils.FixExpressionWithBrackets(obj.VisibleExpression));
  76. if (!obj.Visible)
  77. continue;
  78. }
  79. Translate_Rich(rich);
  80. rich.SecondStageTranslation();
  81. if (useVisibleExpression)
  82. rich.FlagPreviewVisible = false;
  83. }
  84. }
  85. if (obj is TableObject)
  86. {
  87. TranslateTableObject(obj as TableBase);
  88. }
  89. }
  90. }
  91. internal void RestoreRich(RichObject rich)
  92. {
  93. BandBase parentBand = rich.Parent as BandBase;
  94. foreach (ComponentBase obj in rich.TransltedObjects)
  95. {
  96. if (parentBand != null)
  97. {
  98. parentBand.RemoveChild(obj);
  99. parentBand.Objects.Remove(obj);
  100. }
  101. else if (rich.Parent is TableCell)
  102. {
  103. TableCell cell = rich.Parent as TableCell;
  104. cell.RemoveChild(obj);
  105. cell.Objects.Remove(obj);
  106. }
  107. obj.SetParent(null);
  108. }
  109. rich.TransltedObjects.Clear();
  110. }
  111. }
  112. }