HtmlSlide.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using ClearSlideLibrary.Dom;
  5. using System.IO;
  6. namespace ClearSlideLibrary.HtmlController
  7. {
  8. internal class HtmlSlide : HtmlPresentationElement
  9. {
  10. public PPTContainerShape ContainerShape { get; set; }
  11. private readonly string _fileName;
  12. private readonly string dirPath;
  13. private int slideIndex;
  14. public HtmlSlide(string slideid, string slideClass, string fileName, string dirpath, int slideIndex)
  15. {
  16. base.id = slideid;
  17. base.cssClass = slideClass;
  18. this._fileName = fileName;
  19. this.dirPath = dirpath;
  20. this.slideIndex = slideIndex;
  21. }
  22. public override string DrawElement()
  23. {
  24. StringBuilder slideBuilder = new StringBuilder(1000);
  25. slideBuilder.Append("<div class=\"" + cssClass + "\" id=\"" + id + "\"><img />");
  26. try
  27. {
  28. GenerateElements(slideBuilder);
  29. }
  30. catch (ArgumentNullException ex)
  31. {
  32. Console.WriteLine("The slide has no shapes." + ex);
  33. }
  34. slideBuilder.Append("</div>");
  35. return slideBuilder.ToString();
  36. }
  37. private void GenerateElements(StringBuilder slide)
  38. {
  39. if (ContainerShape.Elements.Count > 0)
  40. {
  41. foreach (PPTShapeBase baseShape in ContainerShape.Elements)
  42. {
  43. DrawShapeHtml(slide, baseShape);
  44. }
  45. }
  46. }
  47. private void DrawShapeHtml(StringBuilder slide, PPTShapeBase baseShape)
  48. {
  49. int left = baseShape.VisualShapeProp.Left();
  50. int width = baseShape.VisualShapeProp.PixelWidth();
  51. int top = baseShape.VisualShapeProp.Top();
  52. int height = baseShape.VisualShapeProp.PixelHeight();
  53. string Id = baseShape.NonVisualShapeProp.Id;
  54. bool invisible = baseShape.Invisible;
  55. bool animatable = baseShape.Animatable;
  56. string clickLinkUrl = baseShape.ClickLinkUrl;
  57. //simple fix (not good but work for now).
  58. DirectoryInfo dest = new DirectoryInfo(dirPath);
  59. FileInfo[] files = dest.GetFiles();
  60. foreach (FileInfo file in files)
  61. {
  62. string fname = Path.GetFileNameWithoutExtension(file.Name);
  63. if (fname.Equals(Id))
  64. {
  65. if (baseShape is PPTGraphicFrame)
  66. {
  67. HtmlSmartArt htmlSmartArt = new HtmlSmartArt(Id, width, height, top,
  68. left, invisible, animatable);
  69. slide.Append(htmlSmartArt.DrawElement());
  70. }
  71. else if (baseShape is PPTGroupShape)
  72. {
  73. HtmlGroupShape htmlShape = new HtmlGroupShape(Id, width, height, top,
  74. left, invisible, animatable);
  75. slide.Append(htmlShape.DrawElement());
  76. }
  77. else if (baseShape is PPTConnectionShape)
  78. {
  79. HtmlConnectionShape htmlShape =
  80. new HtmlConnectionShape(Id, width, height, top,
  81. left, invisible, animatable);
  82. slide.Append(htmlShape.DrawElement());
  83. }
  84. else if (baseShape is PPTShape)
  85. {
  86. PPTShape s = (PPTShape)baseShape;
  87. HtmlShape htmlShape = new HtmlShape(Id, width, height, top,
  88. left, invisible, animatable, slideIndex)
  89. {
  90. Shape = s,
  91. Rotate = s.VisualShapeProp.Rotate,
  92. HyperLink = clickLinkUrl
  93. };
  94. slide.Append(htmlShape.DrawElement());
  95. }
  96. else if (baseShape is PPTImage)
  97. {
  98. string imageName = baseShape.NonVisualShapeProp.Name;
  99. //TODO Differentiate between gif and other image types.
  100. //HtmlImageGIF image = new HtmlImageGIF(Id, _fileName, imageName,top, left);
  101. //slide.Append(image.DrawElement());
  102. HtmlImage htmlImage = new HtmlImage(Id, width, height,
  103. top, left, invisible, animatable,((PPTImage)baseShape).FileExtension )
  104. {
  105. HyperLink = clickLinkUrl
  106. };
  107. slide.Append(htmlImage.DrawElement());
  108. }
  109. }
  110. }
  111. }
  112. public override string ToString()
  113. {
  114. Console.WriteLine("The id is:" + id);
  115. Console.WriteLine("The css class is:" + cssClass);
  116. return id + cssClass;
  117. }
  118. }
  119. }