ReportEngine.Rich.cs 3.4 KB

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