|
@@ -6,6 +6,7 @@ using HTEXLib.Builders;
|
|
|
using HTEXLib.Models.Inner;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Xml.Linq;
|
|
|
|
|
@@ -15,6 +16,7 @@ namespace HTEXLib.Models
|
|
|
{
|
|
|
public PPTSlide(SlidePart openXmlPart, int slideIndex, DefaultTextStyle defaultTextStyle,SlideSize SlideSizes, SlideMasterPart slideMasterPart, XElement root,IEnumerable<XElement> media,TableStylesPart tableStylesPart)
|
|
|
{
|
|
|
+
|
|
|
base.tableStylesPart = tableStylesPart;
|
|
|
base.SlidePart = openXmlPart;
|
|
|
base.slideMasterPart = slideMasterPart;
|
|
@@ -30,24 +32,45 @@ namespace HTEXLib.Models
|
|
|
SetSpecificProperties(SlideLayoutPart);
|
|
|
SetBackground(openXmlPart, slideMasterPart);
|
|
|
Id = "s1s0";
|
|
|
- Transition = JSONGenerator.GenerateTransitionAnimationObject(openXmlPart.Slide.Transition);
|
|
|
+ //页面过渡 切换 https://docs.microsoft.com/zh-cn/dotnet/api/documentformat.openxml.presentation.transition?view=openxml-2.8.1
|
|
|
+
|
|
|
+ Transition transition = openXmlPart.Slide.Transition;
|
|
|
+
|
|
|
+ if (transition == null) {
|
|
|
+ transition= openXmlPart.Slide.Descendants<DocumentFormat.OpenXml.Presentation.Transition>().FirstOrDefault();
|
|
|
+ }
|
|
|
+ Transition = JSONGenerator.GenerateTransitionAnimationObject(transition);
|
|
|
Animations = new List<IAnimation>();
|
|
|
AddAnimations(openXmlPart.Slide.Timing, Animations, SlideSizes);
|
|
|
+ AddTimings(openXmlPart.Slide.Timing, Animations, SlideSizes);
|
|
|
+ //TODO 处理layout 及 master 的 Transition Timing。
|
|
|
+ IAnimation transition_animation;
|
|
|
+ IAnimation slide_transition = AddTransition(openXmlPart.Slide.Transition, "slide");
|
|
|
+
|
|
|
+ IAnimation layout_transition = AddTransition(openXmlPart.SlideLayoutPart.SlideLayout.Transition, "layout");
|
|
|
+ IAnimation master_transition = AddTransition(slideMasterPart.SlideMaster.Transition, "master");
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void SetBackground(SlidePart slidePart, SlideMasterPart slideMasterPart)
|
|
|
{
|
|
|
background= slidePart.Slide.CommonSlideData.Background;
|
|
|
+ backgroundFrom = "slide";
|
|
|
if (background == null) {
|
|
|
+ backgroundFrom = "layout";
|
|
|
background = slidePart.SlideLayoutPart.SlideLayout.CommonSlideData.Background;
|
|
|
}
|
|
|
if (background == null) {
|
|
|
+ backgroundFrom = "master";
|
|
|
background = slideMasterPart.SlideMaster.CommonSlideData.Background;
|
|
|
}
|
|
|
}
|
|
|
public List<string> lazyFiles { get; set; } = new List<string>();
|
|
|
public Background background { get; set; }
|
|
|
+ public string backgroundFrom { get; set; }
|
|
|
+
|
|
|
//Slide specific properties
|
|
|
public DefaultTextStyle defaultTextStyle { get; set; }
|
|
|
public PPTContainerShape ContainerShape { get; set; } = new PPTContainerShape();
|
|
@@ -143,6 +166,14 @@ namespace HTEXLib.Models
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void AddTimings(OpenXmlCompositeElement element, List<IAnimation> animations, SlideSize slideSizes)
|
|
|
+ {
|
|
|
+ if (element == null)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
public void AddAnimations(OpenXmlCompositeElement element, List<IAnimation> resultList, SlideSize SlideSizes)
|
|
|
{
|
|
|
if (element == null)
|
|
@@ -215,5 +246,236 @@ namespace HTEXLib.Models
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ private IAnimation AddTransition(Transition trans,string partForm)
|
|
|
+ {
|
|
|
+ if (trans == null || trans.FirstChild == null)
|
|
|
+ return null;
|
|
|
+ TransitionAnimation result = new TransitionAnimation();
|
|
|
+ if (trans.Speed != null && TransitionSpeedValues.Fast.Equals(trans.Speed.Value))
|
|
|
+ result.Length = 500;
|
|
|
+ else if (trans.Speed != null && TransitionSpeedValues.Slow.Equals(trans.Speed.Value))
|
|
|
+ result.Length = 2000;
|
|
|
+ //用于播放 设置持续时长
|
|
|
+ else if (trans.Duration != null)
|
|
|
+ result.Length = int.Parse(trans.Duration.Value);
|
|
|
+ else
|
|
|
+ result.Length = 1000;
|
|
|
+ result.Start = 0;
|
|
|
+ result.InitialState = -1;
|
|
|
+ result.Repetitions = 1;
|
|
|
+ //指定鼠标单击是否推进幻灯片。如果未指定此属性,则假设值为true。
|
|
|
+ if (trans.AdvanceOnClick != null)
|
|
|
+ result.AdvanceOnClick = trans.AdvanceOnClick.Value;
|
|
|
+ else result.AdvanceOnClick = true;
|
|
|
+ //advTm小于 动画总时长 以动画总时长为准
|
|
|
+ //当前页动画时长 |___ _____ ______ __|
|
|
|
+ //当前页advTm时长 |________________|
|
|
|
+ //advTm大于 动画总时长,以advTm 时长为准,动画间隔被平均
|
|
|
+ //当前页动画时长 |___ _____ ______ __|
|
|
|
+ //当前页advTm时长 |_________________________|
|
|
|
+ if (trans.AdvanceAfterTime != null) {
|
|
|
+ result.advTm = int.Parse(trans.AdvanceAfterTime.Value);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (typeof(DocumentFormat.OpenXml.Presentation.BlindsTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<BlindsTransition>();
|
|
|
+ result.Type = AnimationTypes.Blinds;
|
|
|
+ //§19.5.18
|
|
|
+ //Horizontal = 0, horz Vertical = 1 vert
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.CheckerTransition) == trans.FirstChild.GetType()) {
|
|
|
+
|
|
|
+ var child = trans.GetFirstChild<CheckerTransition>();
|
|
|
+ result.Type = AnimationTypes.Checker;
|
|
|
+ // §19.5.24
|
|
|
+ //Horizontal = 0, horz Vertical = 1 vert
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.CircleTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<CircleTransition>();
|
|
|
+ result.Type = AnimationTypes.Circle;
|
|
|
+ // §19.5.26
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type,""} };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.DissolveTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<DissolveTransition>();
|
|
|
+ //§19.5.36
|
|
|
+ result.Type = AnimationTypes.Dissolve;// AnimationTypes.DissolveIn;
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type,""} };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.CombTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<CombTransition>();
|
|
|
+ result.Type = AnimationTypes.Comb;
|
|
|
+ // §19.5.30
|
|
|
+ //Horizontal = 0, horz Vertical = 1 vert
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.CoverTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<CoverTransition>();
|
|
|
+ result.Type = AnimationTypes.Cover;
|
|
|
+ // §19.5.32
|
|
|
+ //u up 默认 , d down , l left ,r right ,ld left down ,lu left up, rd right down ,ru right up
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.CutTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<CutTransition>();
|
|
|
+ result.Type = AnimationTypes.Cut;
|
|
|
+ bool flag = false;
|
|
|
+ if (child.ThroughBlack != null && child.ThroughBlack.Value) {
|
|
|
+ result.Type = AnimationTypes.CutThroughBlack;
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ // §19.5.34
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, flag} };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.DiamondTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<DiamondTransition>();
|
|
|
+ result.Type = AnimationTypes.Diamond;
|
|
|
+ //§19.5.35
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type,"" } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.FadeTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<FadeTransition>();
|
|
|
+ result.Type = AnimationTypes.Fade;
|
|
|
+ bool flag = false;
|
|
|
+ if (child.ThroughBlack != null && child.ThroughBlack.Value)
|
|
|
+ {
|
|
|
+ result.Type = AnimationTypes.FadeThroughBlack;
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ // §19.5.41
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, flag } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.NewsflashTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<NewsflashTransition>();
|
|
|
+ result.Type = AnimationTypes.Newsflash;
|
|
|
+ // §19.5.50
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type,"" } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.PlusTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<PlusTransition>();
|
|
|
+ result.Type = AnimationTypes.Plus;
|
|
|
+ // §19.5.54
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, ""} };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.PullTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<PullTransition>();
|
|
|
+ result.Type = AnimationTypes.Pull;
|
|
|
+ // §19.5.58
|
|
|
+ //u up 默认 , d down , l left ,r right ,ld left down ,lu left up, rd right down ,ru right up
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.PushTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<PushTransition>();
|
|
|
+ result.Type = AnimationTypes.Push;
|
|
|
+ // §19.5.59
|
|
|
+ //u up 默认 d down l left r right
|
|
|
+ result.typeExt =new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.RandomTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<RandomTransition>();
|
|
|
+ result.Type = AnimationTypes.Random;
|
|
|
+ //§19.5.60
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type,"" } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.RandomBarTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<RandomBarTransition>();
|
|
|
+ result.Type = AnimationTypes.RandomBar;
|
|
|
+ // Horizontal = 0, horz Vertical = 1 vert
|
|
|
+ // §19.5.61
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.SplitTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<SplitTransition>();
|
|
|
+ result.Type = AnimationTypes.Split;
|
|
|
+ // Out = 0, out In = 1 in
|
|
|
+ var dir = child.Direction.Value.ToString();
|
|
|
+ // Horizontal = 0, horz Vertical = 1 vert
|
|
|
+ // §19.5.71
|
|
|
+ var orient = child.Orientation.Value.ToString();
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type,new { dir , orient } } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.StripsTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<StripsTransition>();
|
|
|
+ result.Type = AnimationTypes.Strips;
|
|
|
+ // Left-Up lu , Right-Up ru ,Left-Downld , Right-Down rd
|
|
|
+ // §19.5.74
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.WedgeTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<WedgeTransition>();
|
|
|
+ result.Type = AnimationTypes.Wedge;
|
|
|
+ // §19.5.94
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, "" } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.WheelTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<WheelTransition>();
|
|
|
+ result.Type = AnimationTypes.Wheel;
|
|
|
+ //19.5.95
|
|
|
+ // 1,一个扇形中心旋转一圈,右上角开始, 2 两个扇形旋转, 3三个扇形旋转,4 四个扇形旋转, 8 八个扇形旋转
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Spokes.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.WipeTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<WipeTransition>();
|
|
|
+ result.Type = AnimationTypes.Wipe;
|
|
|
+ //u up 默认 , d down , l left ,r right
|
|
|
+ // §19.5.96
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ else if (typeof(DocumentFormat.OpenXml.Presentation.ZoomTransition) == trans.FirstChild.GetType()) {
|
|
|
+ var child = trans.GetFirstChild<ZoomTransition>();
|
|
|
+ result.Type = AnimationTypes.Zoom;
|
|
|
+ // Out = 0, out In = 1 in
|
|
|
+ // §19.5.97
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { result.Type, child.Direction.Value.ToString() } };
|
|
|
+ }
|
|
|
+ var SoundAction = trans.GetFirstChild<SoundAction>();
|
|
|
+ if (SoundAction != null) {
|
|
|
+ var loop = false;
|
|
|
+ if (SoundAction.StartSoundAction.Loop != null) {
|
|
|
+ loop = true;
|
|
|
+ }
|
|
|
+ var url = "";
|
|
|
+ var name = "";
|
|
|
+ if (SoundAction.StartSoundAction.Sound != null) {
|
|
|
+ var Sound = SoundAction.StartSoundAction.Sound;
|
|
|
+
|
|
|
+ var Embed = Sound.Embed;
|
|
|
+ DataPartReferenceRelationship part = null;
|
|
|
+ if (partForm == "slide")
|
|
|
+ {
|
|
|
+ part = SlidePart.DataPartReferenceRelationships.Where(x => x.Id == Embed).FirstOrDefault();
|
|
|
+ }
|
|
|
+ if (partForm == "layout")
|
|
|
+ {
|
|
|
+ part = SlideLayoutPart.DataPartReferenceRelationships.Where(x => x.Id == Embed).FirstOrDefault();
|
|
|
+
|
|
|
+ }
|
|
|
+ if (partForm == "master")
|
|
|
+ {
|
|
|
+ part = slideMasterPart.DataPartReferenceRelationships.Where(x => x.Id == Embed).FirstOrDefault();
|
|
|
+ }
|
|
|
+ if (part != null)
|
|
|
+ {
|
|
|
+ url = part.Uri.ToString().Replace("../", "/ppt/");
|
|
|
+ var thumbnail = Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
|
|
|
+ //if (thumbnail != null)
|
|
|
+ //{
|
|
|
+ // var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
|
|
|
+ // //var data = thumbnail.Value;
|
|
|
+ // //url = "data:" + contentType + ";base64," + data;
|
|
|
+ // //url = url.Replace("\r\n", "");
|
|
|
+ // result.url = url;
|
|
|
+ // // htexBlipFill.urlType = "base64";
|
|
|
+ // // htexBlipFill.contentType = contentType;
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ result.typeExt = new Dictionary<string, object>() { { "sndAc", new { loop, url, name } } };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ///TODO Office2013|Office2010
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
}
|