HtexSlide.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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, TimingId);
  92. items = htmlSmartArt.DrawElement();
  93. }
  94. }
  95. else
  96. {
  97. HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, width, height, top,
  98. left, invisible, animatable, index, graphicFrame, slide, baseShape.PartForm, TimingId);
  99. items = htmlSmartArt.DrawElement();
  100. }
  101. }
  102. else if (baseShape is PPTGroupShape groupShape)
  103. {
  104. if (groupShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  105. {
  106. if (FromGroup)
  107. {
  108. HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
  109. left, invisible, animatable, index, groupShape, slide, baseShape.PartForm, TimingId);
  110. items = htmlShape.DrawElement();
  111. }
  112. }
  113. else
  114. {
  115. HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
  116. left, invisible, animatable, index, groupShape, slide, baseShape.PartForm, TimingId);
  117. items = htmlShape.DrawElement();
  118. }
  119. }
  120. else if (baseShape is PPTConnectionShape connectionShape)
  121. {
  122. if (connectionShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  123. {
  124. if (FromGroup)
  125. {
  126. HtexConnectionShape htmlShape =
  127. new HtexConnectionShape(Id, rot, width, height, top,
  128. left, invisible, animatable, index, connectionShape, slide, baseShape.PartForm, TimingId);
  129. items = htmlShape.DrawElement();
  130. }
  131. }
  132. else
  133. {
  134. HtexConnectionShape htmlShape =
  135. new HtexConnectionShape(Id, rot, width, height, top,
  136. left, invisible, animatable, index, connectionShape, slide, baseShape.PartForm, TimingId);
  137. items = htmlShape.DrawElement();
  138. }
  139. }
  140. else if (baseShape is PPTShape shape)
  141. {
  142. if (shape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  143. {
  144. if (FromGroup)
  145. {
  146. HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
  147. left, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm, TimingId)
  148. {
  149. Shape = shape,
  150. //rot = baseShape.VisualShapeProp.Rotate,
  151. HyperLink = clickLinkUrl
  152. };
  153. items = htmlShape.DrawElement();
  154. }
  155. }
  156. else
  157. {
  158. HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
  159. left, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm, TimingId)
  160. {
  161. Shape = shape,
  162. //rot = baseShape.VisualShapeProp.Rotate,
  163. HyperLink = clickLinkUrl
  164. };
  165. items = htmlShape.DrawElement();
  166. }
  167. }
  168. else if (baseShape is PPTImage image)
  169. {
  170. if (image.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  171. {
  172. if (FromGroup)
  173. {
  174. HtexImage htmlImage = new HtexImage(Id, rot, width, height,
  175. top, left, invisible, animatable, image.FileExtension, index, image, slide, baseShape.PartForm, TimingId)
  176. {
  177. HyperLink = clickLinkUrl
  178. };
  179. items = htmlImage.DrawElement();
  180. }
  181. }
  182. else
  183. {
  184. HtexImage htmlImage = new HtexImage(Id, rot, width, height,
  185. top, left, invisible, animatable, image.FileExtension, index, image, slide, baseShape.PartForm, TimingId)
  186. {
  187. HyperLink = clickLinkUrl
  188. };
  189. items = htmlImage.DrawElement();
  190. }
  191. }
  192. else if (baseShape is PPTMath math)
  193. {
  194. if (math.element.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  195. {
  196. if (FromGroup)
  197. {
  198. HtexMath htexMath = new HtexMath(Id, rot, width, height, top,
  199. left, invisible, animatable, slideIndex, index, math, slide, baseShape.PartForm, TimingId)
  200. {
  201. pptMath = math,
  202. HyperLink = clickLinkUrl
  203. };
  204. items = htexMath.DrawElement();
  205. }
  206. }
  207. else
  208. {
  209. HtexMath htexMath = new HtexMath(Id, rot, width, height, top,
  210. left, invisible, animatable, slideIndex, index, math, slide, baseShape.PartForm, TimingId)
  211. {
  212. pptMath = math,
  213. HyperLink = clickLinkUrl
  214. };
  215. items = htexMath.DrawElement();
  216. }
  217. }
  218. else if(baseShape is PPTTable table){
  219. if (table.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  220. {
  221. if (FromGroup)
  222. {
  223. HtexTable HtexTable = new HtexTable(Id, rot, width, height, top, left, invisible, animatable, index, table.element, slide, baseShape.PartForm, TimingId);
  224. items = HtexTable.DrawElement();
  225. }
  226. }
  227. else
  228. {
  229. HtexTable HtexTable = new HtexTable(Id, rot, width, height, top, left, invisible, animatable, index, table.element, slide, baseShape.PartForm, TimingId);
  230. items = HtexTable.DrawElement();
  231. }
  232. if (items != null && items.Count > 0)
  233. {
  234. items[0].uid = table.suid;
  235. }
  236. }
  237. else if (baseShape is PPTChart Chart)
  238. {
  239. if (Chart.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  240. {
  241. if (FromGroup)
  242. {
  243. HtexChart HtexChart = new HtexChart(Id, rot, width, height, top, left, invisible, animatable, index, Chart.element, slide, baseShape.PartForm, TimingId);
  244. items = HtexChart.DrawElement();
  245. }
  246. }
  247. else
  248. {
  249. HtexChart HtexChart = new HtexChart(Id, rot, width, height, top, left, invisible, animatable, index, Chart.element, slide, baseShape.PartForm, TimingId);
  250. items = HtexChart.DrawElement();
  251. }
  252. if (items != null && items.Count > 0)
  253. {
  254. items[0].uid = Chart.suid;
  255. }
  256. }
  257. else if (baseShape is PPTDiagram Diagram)
  258. {
  259. if (Diagram.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
  260. {
  261. if (FromGroup)
  262. {
  263. HtexDiagram HtexChart = new HtexDiagram(Id, rot, width, height, top, left, invisible, animatable, index, Diagram.element, slide, baseShape.PartForm, TimingId);
  264. items = HtexChart.DrawElement();
  265. }
  266. }
  267. else
  268. {
  269. HtexDiagram HtexChart = new HtexDiagram(Id, rot, width, height, top, left, invisible, animatable, index, Diagram.element, slide, baseShape.PartForm, TimingId);
  270. items = HtexChart.DrawElement();
  271. }
  272. if (items != null && items.Count > 0)
  273. {
  274. items[0].uid = Diagram.suid;
  275. }
  276. }
  277. if (items != null && items.Count > 0) {
  278. items[0].animations = simpleAnimations;
  279. items[0].animatable = animatable;
  280. }
  281. return items;
  282. }
  283. public override string ToString()
  284. {
  285. return slide.Id ;
  286. }
  287. }
  288. }