HtexSlide.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using DocumentFormat.OpenXml.Drawing;
  2. using HTEXLib.Animations;
  3. using HTEXLib.Helpers.ShapeHelpers;
  4. using HTEXLib.Models.Inner;
  5. using HTEXLib.Models.PPTX;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. namespace HTEXLib.Models.HTEX
  11. {
  12. public class HtexSlide : HtexElement
  13. {
  14. public PPTContainerShape ContainerShape { get; set; }
  15. public bool FromGroup { get; set; } = false;
  16. private int slideIndex;
  17. public HtexSlide(PPTSlide slide, int slideIndex) {
  18. base.slide = slide;
  19. //base.cssClass = slideClass;
  20. this.slideIndex = slideIndex;
  21. }
  22. public override List<Item> DrawElement()
  23. {
  24. List<Item> htexElements = new List<Item>();
  25. List<Item> items = GenerateElements();
  26. if (items != null) {
  27. htexElements.AddRange(items);
  28. }
  29. return htexElements;
  30. }
  31. private List<Item> GenerateElements()
  32. {
  33. List<Item> htexElements = null;
  34. if (ContainerShape.Elements.Count > 0)
  35. {
  36. htexElements = new List<Item>();
  37. int index = 0;
  38. foreach (PPTShapeBase baseShape in ContainerShape.Elements)
  39. {
  40. var items = DrawShapeHtex(baseShape, index);
  41. if (items != null)
  42. {
  43. htexElements.AddRange(items);
  44. }
  45. index++;
  46. }
  47. }
  48. return htexElements;
  49. }
  50. public void doAmt(List<IAnimation> animations, string TimingId, List<IAnimation> simpleAnimations)
  51. {
  52. if (animations != null) {
  53. foreach (IAnimation animation in animations) {
  54. if (animation.ObjectId == TimingId) {
  55. simpleAnimations.Add(animation);
  56. }
  57. if (animation.InnerAnimations != null && animation.InnerAnimations.Count > 0) {
  58. doAmt(animation.InnerAnimations, TimingId, simpleAnimations);
  59. }
  60. }
  61. }
  62. }
  63. private List<Item> DrawShapeHtex( PPTShapeBase baseShape,int index)
  64. {
  65. double left = baseShape.VisualShapeProp.Left();
  66. double width = baseShape.VisualShapeProp.PixelWidth();
  67. double top = baseShape.VisualShapeProp.Top();
  68. double height = baseShape.VisualShapeProp.PixelHeight();
  69. double rot = baseShape.VisualShapeProp.Rotate;
  70. string Id = baseShape.NonVisualShapeProp.Id;
  71. bool invisible = baseShape.Invisible;
  72. bool animatable = baseShape.Animatable;
  73. string clickLinkUrl = baseShape.ClickLinkUrl;
  74. string TimingId = baseShape.NonVisualShapeProp.TimingId;
  75. List<IAnimation> animations= slide.Animations;
  76. List<IAnimation> simpleAnimations = new List<IAnimation>() ;
  77. if (animations != null && animations.Count>0) {
  78. doAmt(animations, TimingId, simpleAnimations);
  79. }
  80. if (simpleAnimations != null && simpleAnimations.Count > 0) {
  81. animatable = true;
  82. }
  83. List<Item> items = null;
  84. if (baseShape is PPTGraphicFrame graphicFrame)
  85. {
  86. if (graphicFrame.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  87. {
  88. if (FromGroup)
  89. {
  90. HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, width, height, top,
  91. left, invisible, animatable, index, graphicFrame, slide, baseShape.PartForm);
  92. items = htmlSmartArt.DrawElement();
  93. }
  94. }
  95. else {
  96. HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, width, height, top,
  97. left, invisible, animatable, index, graphicFrame, slide, baseShape.PartForm);
  98. items = htmlSmartArt.DrawElement();
  99. }
  100. }
  101. else if (baseShape is PPTGroupShape groupShape)
  102. {
  103. if (groupShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  104. {
  105. if (FromGroup)
  106. {
  107. HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
  108. left, invisible, animatable, index, groupShape, slide, baseShape.PartForm);
  109. items = htmlShape.DrawElement();
  110. }
  111. }
  112. else {
  113. HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
  114. left, invisible, animatable, index, groupShape, slide, baseShape.PartForm);
  115. items = htmlShape.DrawElement();
  116. }
  117. }
  118. else if (baseShape is PPTConnectionShape connectionShape)
  119. {
  120. if (connectionShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  121. {
  122. if (FromGroup)
  123. {
  124. HtexConnectionShape htmlShape =
  125. new HtexConnectionShape(Id, rot, width, height, top,
  126. left, invisible, animatable, index, connectionShape, slide, baseShape.PartForm);
  127. items = htmlShape.DrawElement();
  128. }
  129. }
  130. else {
  131. HtexConnectionShape htmlShape =
  132. new HtexConnectionShape(Id, rot, width, height, top,
  133. left, invisible, animatable, index, connectionShape, slide, baseShape.PartForm);
  134. items = htmlShape.DrawElement();
  135. }
  136. }
  137. else if (baseShape is PPTShape shape)
  138. {
  139. if (shape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  140. {
  141. if (FromGroup) {
  142. HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
  143. left, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm)
  144. {
  145. Shape = shape,
  146. //rot = baseShape.VisualShapeProp.Rotate,
  147. HyperLink = clickLinkUrl
  148. };
  149. items = htmlShape.DrawElement();
  150. }
  151. }
  152. else {
  153. HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
  154. left, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm)
  155. {
  156. Shape = shape,
  157. //rot = baseShape.VisualShapeProp.Rotate,
  158. HyperLink = clickLinkUrl
  159. };
  160. items = htmlShape.DrawElement();
  161. }
  162. }
  163. else if (baseShape is PPTImage image)
  164. {
  165. if (image.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  166. {
  167. if (FromGroup)
  168. {
  169. HtexImage htmlImage = new HtexImage(Id, rot, width, height,
  170. top, left, invisible, animatable, image.FileExtension, index, image, slide, baseShape.PartForm)
  171. {
  172. HyperLink = clickLinkUrl
  173. };
  174. items = htmlImage.DrawElement();
  175. }
  176. }
  177. else {
  178. HtexImage htmlImage = new HtexImage(Id, rot, width, height,
  179. top, left, invisible, animatable, image.FileExtension, index, image, slide, baseShape.PartForm)
  180. {
  181. HyperLink = clickLinkUrl
  182. };
  183. items = htmlImage.DrawElement();
  184. }
  185. }
  186. else if (baseShape is PPTMath math) {
  187. if (math.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  188. {
  189. if (FromGroup)
  190. {
  191. HtexMath htexMath = new HtexMath(Id, rot, width, height, top,
  192. left, invisible, animatable, slideIndex, index, math, slide, baseShape.PartForm)
  193. {
  194. pptMath = math,
  195. HyperLink = clickLinkUrl
  196. };
  197. items = htexMath.DrawElement();
  198. }
  199. }
  200. else {
  201. HtexMath htexMath = new HtexMath(Id, rot, width, height, top,
  202. left, invisible, animatable, slideIndex, index, math, slide, baseShape.PartForm)
  203. {
  204. pptMath = math,
  205. HyperLink = clickLinkUrl
  206. };
  207. items = htexMath.DrawElement();
  208. }
  209. }
  210. if (items != null && items.Count > 0) {
  211. items[0].animations = simpleAnimations;
  212. items[0].animatable = animatable;
  213. }
  214. return items;
  215. }
  216. public override string ToString()
  217. {
  218. return slide.Id ;
  219. }
  220. }
  221. }