SimpleAnimation.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using DocumentFormat.OpenXml.Presentation;
  5. using HTEXLib.Models.Inner;
  6. namespace HTEXLib.Animations
  7. {
  8. public class SimpleAnimation : IAnimation
  9. {
  10. public SimpleAnimation()
  11. {
  12. AdditionalData = "0";
  13. ObjectId = "0";
  14. }
  15. public int Start { get; set; }
  16. public int Length { get; set; }
  17. public string ObjectId { get; set; }
  18. public int Repetitions { get; set; }
  19. /// <summary>
  20. /// 1 进入 , 2 退出,3 强调 ,4 路径
  21. /// </summary>
  22. public int InitialState { get; set; }
  23. public string Type { get; set; }
  24. public string AdditionalData { get; set; }
  25. public List<IAnimation> InnerAnimations { get; set; }
  26. public DocumentFormat.OpenXml.EnumValue<DocumentFormat.OpenXml.Presentation.TimeNodeValues> timingType { get; set; }
  27. public int getCalculatedLength()
  28. {
  29. if (InnerAnimations == null || InnerAnimations.Count == 0)
  30. return Length;
  31. int res = 0;
  32. foreach (SimpleAnimation anim in InnerAnimations)
  33. res = res < anim.getCalculatedLength() + anim.Start ? anim.getCalculatedLength() + anim.Start : res;
  34. return res;
  35. }
  36. public bool IsItEntranceAnimation()
  37. {
  38. return InitialState == 1; //I am not sure if it is correct ;)
  39. }
  40. protected string GetObjectIdForJSON()
  41. {
  42. int res = 0;
  43. string result = int.TryParse(ObjectId, out res) ? ObjectId : "'" + ObjectId + "'";
  44. return result;
  45. }
  46. protected string GetE3Value()
  47. {
  48. int res = 0;
  49. string result = int.TryParse(ObjectId, out res) ? "" : ",e3:['s1s" + ObjectId + "']";
  50. return result;
  51. }
  52. public virtual string GetJsonString()
  53. {
  54. return "{objectId:" + GetObjectIdForJSON() + ",start:" + Start + ",length:" + Length + ",repeat:" + Repetitions + ",state:" + InitialState +
  55. ",name:'" + Type + "',additionalData:" + AdditionalData + ",v:0" + ",e0:" + GetE0Value() + ",e1:1,e2:0" + GetE3Value()
  56. + "}";
  57. }
  58. protected string GetE0Value()//if image then 3 else 2
  59. {
  60. int res = 0;
  61. return int.TryParse(ObjectId, out res) ? "3" : "2";
  62. }
  63. public void FixAnimationTimings(CommonBehavior behavior, int slideIndex)
  64. {
  65. String intValue = behavior.TargetElement.ShapeTarget.ShapeId.Value;
  66. ObjectId = intValue == null ? "" + 0 : intValue;
  67. int spd = behavior.CommonTimeNode.Speed == null ? 100 : behavior.CommonTimeNode.Speed.Value;
  68. intValue = behavior.CommonTimeNode.Duration;
  69. Length = intValue == null || intValue == "indefinite" ? 0 : int.Parse(intValue) * spd / 100;
  70. int delay = 0;
  71. if (behavior.CommonTimeNode.StartConditionList != null &&
  72. behavior.CommonTimeNode.StartConditionList.Any())
  73. {
  74. foreach (Condition cond in behavior.CommonTimeNode.StartConditionList)
  75. if (cond.Delay != null && cond.Delay.HasValue)
  76. delay = delay + int.Parse(cond.Delay.Value);
  77. }
  78. if (behavior.TargetElement.ShapeTarget.TextElement != null && behavior.TargetElement.ShapeTarget.TextElement.ParagraphIndexRange != null)
  79. {
  80. int res = 0;
  81. bool isTextWithEffect = int.TryParse(ObjectId, out res) && PPTShape.effectShapes.Contains(slideIndex + "_" + res);
  82. if (!isTextWithEffect)
  83. {
  84. ObjectId = ObjectId + "p" + behavior.TargetElement.ShapeTarget.TextElement.ParagraphIndexRange.Start;
  85. }
  86. //TODO: add support for paragraph start-end index range
  87. }
  88. intValue = behavior.CommonTimeNode.RepeatDuration;
  89. Repetitions = intValue == null ? 1 : int.Parse(intValue);
  90. InnerAnimations = new List<IAnimation>();
  91. Start = delay;
  92. }
  93. }
  94. }