HtexImage.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using DocumentFormat.OpenXml.Drawing;
  2. using HTEXLib.Helpers.ShapeHelpers;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace HTEXLib.Models.HTEX
  8. {
  9. public class HtexImage : HtexElement
  10. {
  11. public string HyperLink { get; set; }
  12. public string FileExtension { get; set; }
  13. public HtexImage(string id, double rot, double width, double height,
  14. double top, double left, bool invisible,
  15. bool animatable, string extension,int index, Inner.PPTImage image, PPTSlide slide, string partForm, string timingId)
  16. {
  17. base.sid = timingId;
  18. base.slide = slide;
  19. this.rot = rot;
  20. this.image = image;
  21. base.id = id;
  22. base.top = top;
  23. base.left = left;
  24. base.width = width;
  25. base.height = height;
  26. base.invisible = invisible;
  27. base.animatable = animatable;
  28. this.FileExtension = extension;
  29. base.index = index;
  30. base.type = "Media";
  31. base.partForm = partForm;
  32. }
  33. public Inner.PPTImage image { get; set; }
  34. public override List<Item> DrawElement()
  35. {
  36. Position position = new Position { cx = width, cy = height, x = left, y = top, rot = rot };
  37. var ShapeStyle = PPTXHelper.DoShapeProperties(image.element.ShapeProperties, slide,type,partForm);
  38. Media media = new Media() { sid = sid, id = this.id, mediaType = "image",type=type,index=index/*,animatable=animatable ,invisible=invisible*/};
  39. media.style.position = position;
  40. media.style.effect = ShapeStyle.effect;
  41. /*
  42. * cNvPicPr (非可视图片绘图属性) §19.3.1.11
  43. cNvPr (非可视绘图属性) §19.3.1.12
  44. nvPr (非可视属性) §19.3.1.33
  45. */
  46. var WaveAudioFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<WaveAudioFile>();
  47. var AudioFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<AudioFromFile>();
  48. var VideoFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<VideoFromFile>();
  49. if (WaveAudioFile != null) {
  50. }
  51. if (AudioFromFile != null) {
  52. string url = AudioFromFile.Link;
  53. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  54. if (part != null) {
  55. url = part.Uri.ToString().Replace("../", "/ppt/");
  56. HtexBlipFill file = new HtexBlipFill { url = url };
  57. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  58. if (thumbnail != null) {
  59. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  60. //file.contentType = contentType;
  61. }
  62. media.mediaType = "audio";
  63. media.file = file;
  64. }
  65. }
  66. if (VideoFromFile != null) {
  67. string url = VideoFromFile.Link;
  68. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  69. if (part != null)
  70. {
  71. url = part.Uri.ToString().Replace("../", "/ppt/");
  72. HtexBlipFill file = new HtexBlipFill { url = url };
  73. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  74. if (thumbnail != null)
  75. {
  76. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  77. // file.contentType = contentType;
  78. }
  79. media.mediaType = "video";
  80. media.file = file;
  81. }
  82. }
  83. SlideColor slideColor = PPTXHelper.DoShapeStyle(image.element.ShapeStyle, slide,type);
  84. //从ShapeProperties 获取 p:spPr
  85. //再从 ShapeStyle 获取 p:spPr
  86. if (ShapeStyle.border == null || ShapeStyle.border.color == null || ShapeStyle.border.color.type == -1)
  87. {
  88. if (slideColor != null)
  89. {
  90. media.style.border.color.solidFill = slideColor.LineColor;
  91. media.style.border.color.type = 2;
  92. }
  93. }
  94. else
  95. {
  96. media.style.border = ShapeStyle.border;
  97. }
  98. if (ShapeStyle.fill == null || ShapeStyle.fill.type == -1)
  99. {
  100. if (slideColor != null)
  101. {
  102. media.style.fill.solidFill = slideColor.FillColor;
  103. media.style.fill.type = 2;
  104. }
  105. }
  106. else
  107. {
  108. media.style.fill = ShapeStyle.fill;
  109. }
  110. HtexBlipFill htexBlipFill = PPTXHelper.DoBlipFill(image.element.BlipFill, slide,partForm);
  111. media.image = htexBlipFill;
  112. media.uid = image.suid;
  113. if (media.style.fill.type == -1|| media.style.fill.type == 0) {
  114. media.style.fill = null;
  115. }
  116. if (media.style.border != null && (media.style.border.color.type == -1|| media.style.border.color.type == 0))
  117. {
  118. media.style.border.color = null;
  119. }
  120. if (media.style.border != null && media.style.border.type == "none")
  121. {
  122. media.style.border = null;
  123. }
  124. //TODO 处理公式图片
  125. return new List<Item>() { media };
  126. }
  127. }
  128. }