123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- using DocumentFormat.OpenXml.Drawing;
- using HTEXLib.Animations;
- using HTEXLib.Helpers.ShapeHelpers;
- using HTEXLib.Models.Inner;
- using HTEXLib.Models.PPTX;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace HTEXLib.Models.HTEX
- {
- public class HtexSlide : HtexElement
- {
- public PPTContainerShape ContainerShape { get; set; }
- public bool FromGroup { get; set; } = false;
- private int slideIndex;
- public HtexSlide(PPTSlide slide, int slideIndex) {
- base.slide = slide;
- //base.cssClass = slideClass;
- this.slideIndex = slideIndex;
- }
- public override List<Item> DrawElement()
- {
- List<Item> htexElements = new List<Item>();
- List<Item> items = GenerateElements();
- if (items != null) {
- htexElements.AddRange(items);
- }
-
- return htexElements;
- }
- private List<Item> GenerateElements()
- {
- List<Item> htexElements = null;
- if (ContainerShape.Elements.Count > 0)
- {
- htexElements = new List<Item>();
- int index = 0;
- foreach (PPTShapeBase baseShape in ContainerShape.Elements)
- {
- var items = DrawShapeHtex(baseShape, index);
- if (items != null)
- {
- htexElements.AddRange(items);
- }
- index++;
- }
- }
- return htexElements;
- }
-
- public void doAmt(List<IAnimation> animations, string TimingId, List<IAnimation> simpleAnimations)
- {
- if (animations != null) {
- foreach (IAnimation animation in animations) {
- if (animation.ObjectId == TimingId) {
- simpleAnimations.Add(animation);
- }
- if (animation.InnerAnimations != null && animation.InnerAnimations.Count > 0) {
- doAmt(animation.InnerAnimations, TimingId, simpleAnimations);
- }
- }
- }
-
- }
- private List<Item> DrawShapeHtex( PPTShapeBase baseShape,int index)
- {
- double left = baseShape.VisualShapeProp.Left();
- double width = baseShape.VisualShapeProp.PixelWidth();
- double top = baseShape.VisualShapeProp.Top();
- double height = baseShape.VisualShapeProp.PixelHeight();
- double rot = baseShape.VisualShapeProp.Rotate;
- string Id = baseShape.NonVisualShapeProp.Id;
- bool invisible = baseShape.Invisible;
- bool animatable = baseShape.Animatable;
-
- string clickLinkUrl = baseShape.ClickLinkUrl;
- string TimingId = baseShape.NonVisualShapeProp.TimingId;
- List<IAnimation> animations= slide.Animations;
- List<IAnimation> simpleAnimations = new List<IAnimation>() ;
- if (animations != null && animations.Count>0) {
- doAmt(animations, TimingId, simpleAnimations);
- }
- if (simpleAnimations != null && simpleAnimations.Count > 0) {
- animatable = true;
- }
- List<Item> items = null;
- if (baseShape is PPTGraphicFrame graphicFrame)
- {
- if (graphicFrame.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, width, height, top,
- left, invisible, animatable, index, graphicFrame, slide, baseShape.PartForm, TimingId);
- items = htmlSmartArt.DrawElement();
- }
- }
- else
- {
- HtexGraphicFrame htmlSmartArt = new HtexGraphicFrame(Id, rot, width, height, top,
- left, invisible, animatable, index, graphicFrame, slide, baseShape.PartForm, TimingId);
- items = htmlSmartArt.DrawElement();
- }
- }
- else if (baseShape is PPTGroupShape groupShape)
- {
- if (groupShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
- left, invisible, animatable, index, groupShape, slide, baseShape.PartForm, TimingId);
- items = htmlShape.DrawElement();
- }
- }
- else
- {
- HtexGroupShape htmlShape = new HtexGroupShape(Id, rot, width, height, top,
- left, invisible, animatable, index, groupShape, slide, baseShape.PartForm, TimingId);
- items = htmlShape.DrawElement();
- }
- }
- else if (baseShape is PPTConnectionShape connectionShape)
- {
- if (connectionShape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexConnectionShape htmlShape =
- new HtexConnectionShape(Id, rot, width, height, top,
- left, invisible, animatable, index, connectionShape, slide, baseShape.PartForm, TimingId);
- items = htmlShape.DrawElement();
- }
- }
- else
- {
- HtexConnectionShape htmlShape =
- new HtexConnectionShape(Id, rot, width, height, top,
- left, invisible, animatable, index, connectionShape, slide, baseShape.PartForm, TimingId);
- items = htmlShape.DrawElement();
- }
- }
- else if (baseShape is PPTShape shape)
- {
- if (shape.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
- left, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm, TimingId)
- {
- Shape = shape,
- //rot = baseShape.VisualShapeProp.Rotate,
- HyperLink = clickLinkUrl
- };
- items = htmlShape.DrawElement();
- }
- }
- else
- {
- HtexShape htmlShape = new HtexShape(Id, rot, width, height, top,
- left, invisible, animatable, slideIndex, index, shape, slide, baseShape.PartForm, TimingId)
- {
- Shape = shape,
- //rot = baseShape.VisualShapeProp.Rotate,
- HyperLink = clickLinkUrl
- };
- items = htmlShape.DrawElement();
- }
- }
- else if (baseShape is PPTImage image)
- {
- if (image.element.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexImage htmlImage = new HtexImage(Id, rot, width, height,
- top, left, invisible, animatable, image.FileExtension, index, image, slide, baseShape.PartForm, TimingId)
- {
- HyperLink = clickLinkUrl
- };
- items = htmlImage.DrawElement();
- }
- }
- else
- {
- HtexImage htmlImage = new HtexImage(Id, rot, width, height,
- top, left, invisible, animatable, image.FileExtension, index, image, slide, baseShape.PartForm, TimingId)
- {
- HyperLink = clickLinkUrl
- };
- items = htmlImage.DrawElement();
- }
- }
- else if (baseShape is PPTMath math)
- {
- if (math.element.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexMath htexMath = new HtexMath(Id, rot, width, height, top,
- left, invisible, animatable, slideIndex, index, math, slide, baseShape.PartForm, TimingId)
- {
- pptMath = math,
- HyperLink = clickLinkUrl
- };
- items = htexMath.DrawElement();
- }
- }
- else
- {
- HtexMath htexMath = new HtexMath(Id, rot, width, height, top,
- left, invisible, animatable, slideIndex, index, math, slide, baseShape.PartForm, TimingId)
- {
- pptMath = math,
- HyperLink = clickLinkUrl
- };
- items = htexMath.DrawElement();
- }
- }
- else if(baseShape is PPTTable table){
- if (table.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexTable HtexTable = new HtexTable(Id, rot, width, height, top, left, invisible, animatable, index, table.element, slide, baseShape.PartForm, TimingId);
-
- items = HtexTable.DrawElement();
-
- }
- }
- else
- {
- HtexTable HtexTable = new HtexTable(Id, rot, width, height, top, left, invisible, animatable, index, table.element, slide, baseShape.PartForm, TimingId);
- items = HtexTable.DrawElement();
- }
- if (items != null && items.Count > 0)
- {
- items[0].uid = table.suid;
- }
- }
- else if (baseShape is PPTChart Chart)
- {
- if (Chart.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexChart HtexChart = new HtexChart(Id, rot, width, height, top, left, invisible, animatable, index, Chart.element, slide, baseShape.PartForm, TimingId);
- items = HtexChart.DrawElement();
- }
- }
- else
- {
- HtexChart HtexChart = new HtexChart(Id, rot, width, height, top, left, invisible, animatable, index, Chart.element, slide, baseShape.PartForm, TimingId);
- items = HtexChart.DrawElement();
- }
- if (items != null && items.Count > 0)
- {
- items[0].uid = Chart.suid;
- }
- }
- else if (baseShape is PPTDiagram Diagram)
- {
- if (Diagram.element.Parent.Parent.Parent.Parent.Parent.Parent is DocumentFormat.OpenXml.Presentation.GroupShape)
- {
- if (FromGroup)
- {
- HtexDiagram HtexChart = new HtexDiagram(Id, rot, width, height, top, left, invisible, animatable, index, Diagram.element, slide, baseShape.PartForm, TimingId);
- items = HtexChart.DrawElement();
- }
- }
- else
- {
- HtexDiagram HtexChart = new HtexDiagram(Id, rot, width, height, top, left, invisible, animatable, index, Diagram.element, slide, baseShape.PartForm, TimingId);
- items = HtexChart.DrawElement();
- }
- if (items != null && items.Count > 0)
- {
- items[0].uid = Diagram.suid;
- }
- }
- if (items != null && items.Count > 0) {
- items[0].animations = simpleAnimations;
- items[0].animatable = animatable;
- }
- return items;
- }
- public override string ToString()
- {
- return slide.Id ;
- }
- }
- }
|