SimpleAnimation.cs 4.1 KB

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