EmphasisAnimation.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using DocumentFormat.OpenXml.Presentation;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using DocumentFormat.OpenXml.Drawing;
  6. using DocumentFormat.OpenXml;
  7. using ClearSlideLibrary.Dom;
  8. namespace ClearSlideLibrary.Animations
  9. {
  10. public class EmphasisAnimation : SimpleAnimation
  11. {
  12. public EmphasisAnimation()
  13. {
  14. }
  15. public EmphasisAnimation(SimpleAnimation fromBase)
  16. {
  17. this.AdditionalData = fromBase.AdditionalData;
  18. this.InitialState = fromBase.InitialState;
  19. this.InnerAnimations = fromBase.InnerAnimations;
  20. this.Start = fromBase.Start;
  21. this.Length = fromBase.Length;
  22. this.ObjectId = fromBase.ObjectId;
  23. this.Repetitions = fromBase.Repetitions;
  24. this.timingType = fromBase.timingType;
  25. this.Type = fromBase.Type;
  26. this.RGBColor = "[0,0,0]";
  27. this.Transparency = 0;
  28. this.RotationDegrees = 0;
  29. this.ScaleX = 0;
  30. this.ScaleY = 0;
  31. e1 = 1;
  32. e2 = 0;
  33. }
  34. public String RGBColor { get; set; }
  35. public double Transparency { get; set; }
  36. public int ScaleX { get; set; }
  37. public int ScaleY { get; set; }
  38. public int RotationDegrees { get; set; }
  39. public int e1 { get; set; }
  40. public int e2 { get; set; }
  41. public override string GetJsonString()
  42. {
  43. return "{objectId:" + GetObjectIdForJSON() + ",start:" + Start + ",length:" + Length + ",repeat:" + Repetitions + ",state:" + InitialState +
  44. ",name:'" + Type + "',c7:0,additionalData:" + RotationDegrees + ",additionalData2:" + RotationDegrees + ",scaleX:" + ScaleX + ",scaleY:" + ScaleY +
  45. ",color:" + RGBColor + ",transparency:" +
  46. Transparency.ToString("0.##", System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat) + ",v:0,e0:" + GetE0Value() + ",e1:" + e1 + ",e2:" + e2 + GetE3Value() + "}";
  47. }
  48. public void setRgbColor(CommonTimeNode commonTimeNode, PPTSlide Slide)
  49. {
  50. RGBColor = "[0,0,0]";
  51. foreach (Object xmlEl in commonTimeNode.Descendants())
  52. {
  53. if (xmlEl.GetType().Equals(typeof(RgbColorModelHex)))
  54. {
  55. RgbColorModelHex rgb = (RgbColorModelHex)xmlEl;
  56. RGBColor = convertHEXtoRGB(((RgbColorModelHex)rgb).Val);
  57. }
  58. else if (xmlEl.GetType().Equals(typeof(SchemeColor)))
  59. {
  60. string schemeCol = ((SchemeColor)xmlEl).Val;
  61. DocumentFormat.OpenXml.Drawing.ColorScheme allSchemeCols =
  62. Slide.SlideLayoutPart.SlideMasterPart.ThemePart.Theme.ThemeElements.ColorScheme;
  63. foreach (OpenXmlCompositeElement desc in allSchemeCols.Descendants())
  64. {
  65. string currSchemeCol = desc.LocalName;
  66. if (schemeCol == currSchemeCol ||
  67. (schemeCol == "bg1" && currSchemeCol == "lt1") ||
  68. (schemeCol == "bg2" && currSchemeCol == "lt2") ||
  69. (schemeCol == "tx1" && currSchemeCol == "dk1") ||
  70. (schemeCol == "tx2" && currSchemeCol == "dk2"))
  71. {
  72. if (typeof(RgbColorModelHex) == desc.FirstChild.GetType())
  73. {
  74. RGBColor = convertHEXtoRGB(((RgbColorModelHex)desc.FirstChild).Val);
  75. }
  76. else if (typeof(SystemColor) == desc.FirstChild.GetType())
  77. {
  78. RGBColor = convertHEXtoRGB(((SystemColor)desc.FirstChild).LastColor);
  79. }
  80. }
  81. }
  82. break;
  83. }
  84. }
  85. }
  86. private string convertHEXtoRGB(string hex)
  87. {
  88. var colorHtml = System.Drawing.ColorTranslator.FromHtml("#" + hex);
  89. string rgb = "[" + colorHtml.R + "," + colorHtml.G + "," + colorHtml.B + "]";
  90. return rgb;
  91. }
  92. }
  93. }