HtexSlide.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using DocumentFormat.OpenXml.Drawing;
  2. using HTEXLib.Helpers.ShapeHelpers;
  3. using HTEXLib.Models.Inner;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace HTEXLib.Models.HTEX
  8. {
  9. public class HtexSlide : HtexElement
  10. {
  11. public PPTContainerShape ContainerShape { get; set; }
  12. private int slideIndex;
  13. public HtexSlide(PPTSlide slide, int slideIndex) {
  14. base.slide = slide;
  15. //base.cssClass = slideClass;
  16. this.slideIndex = slideIndex;
  17. }
  18. public override List<Item> DrawElement()
  19. {
  20. List<Item> htexElements = new List<Item>();
  21. List<Item> items = GenerateElements();
  22. if (items != null) {
  23. htexElements.AddRange(items);
  24. }
  25. return htexElements;
  26. }
  27. private List<Item> GenerateElements()
  28. {
  29. List<Item> htexElements = null;
  30. if (ContainerShape.Elements.Count > 0)
  31. {
  32. htexElements = new List<Item>();
  33. int index = 0;
  34. foreach (PPTShapeBase baseShape in ContainerShape.Elements)
  35. {
  36. var a = DrawShapeHtex(baseShape, index);
  37. if (a != null)
  38. {
  39. htexElements.AddRange(a);
  40. }
  41. index++;
  42. }
  43. }
  44. return htexElements;
  45. }
  46. private List<Item> DrawShapeHtex( PPTShapeBase baseShape,int index)
  47. {
  48. double left = baseShape.VisualShapeProp.Left();
  49. double width = baseShape.VisualShapeProp.PixelWidth();
  50. double top = baseShape.VisualShapeProp.Top();
  51. double height = baseShape.VisualShapeProp.PixelHeight();
  52. double rot = baseShape.VisualShapeProp.Rotate;
  53. string Id = baseShape.NonVisualShapeProp.Id;
  54. bool invisible = baseShape.Invisible;
  55. bool animatable = baseShape.Animatable;
  56. string clickLinkUrl = baseShape.ClickLinkUrl;
  57. if (baseShape is PPTGraphicFrame graphicFrame)
  58. {
  59. HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, width, height, top,
  60. left, invisible, animatable ,index,graphicFrame,slide,baseShape.PartForm);
  61. return htmlSmartArt.DrawElement();
  62. }
  63. else if (baseShape is PPTGroupShape groupShape)
  64. {
  65. HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
  66. left, invisible, animatable,index, groupShape, slide, baseShape.PartForm);
  67. return htmlShape.DrawElement();
  68. }
  69. else if (baseShape is PPTConnectionShape connectionShape)
  70. {
  71. HtexConnectionShape htmlShape =
  72. new HtexConnectionShape(Id, rot, width, height, top,
  73. left, invisible, animatable,index, connectionShape, slide, baseShape.PartForm);
  74. return htmlShape.DrawElement();
  75. }
  76. else if (baseShape is PPTShape shape)
  77. {
  78. HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
  79. left, invisible, animatable, slideIndex,index, shape, slide, baseShape.PartForm)
  80. {
  81. Shape = shape,
  82. //rot = baseShape.VisualShapeProp.Rotate,
  83. HyperLink = clickLinkUrl
  84. };
  85. return htmlShape.DrawElement();
  86. }
  87. else if (baseShape is PPTImage image)
  88. {
  89. string imageName = baseShape.NonVisualShapeProp.Name;
  90. //TODO Differentiate between gif and other image types.
  91. //HtexImageGIF image = new HtexImageGIF(Id, _fileName, imageName,top, left);
  92. //slide.Append(image.DrawElement());
  93. HtexImage htmlImage = new HtexImage(Id, rot, width, height,
  94. top, left, invisible, animatable, image.FileExtension,index, image, slide, baseShape.PartForm)
  95. {
  96. HyperLink = clickLinkUrl
  97. };
  98. return htmlImage.DrawElement();
  99. }
  100. else {
  101. return null;
  102. }
  103. }
  104. public override string ToString()
  105. {
  106. Console.WriteLine("The id is:" + slide.Id);
  107. // Console.WriteLine("The css class is:" + cssClass);
  108. return slide.Id ;
  109. }
  110. }
  111. }