HtexImage.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /*
  41. * cNvPicPr (非可视图片绘图属性) §19.3.1.11
  42. cNvPr (非可视绘图属性) §19.3.1.12
  43. nvPr (非可视属性) §19.3.1.33
  44. */
  45. var WaveAudioFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<WaveAudioFile>();
  46. var AudioFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<AudioFromFile>();
  47. var VideoFromFile = image.element.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<VideoFromFile>();
  48. if (WaveAudioFile != null) {
  49. }
  50. if (AudioFromFile != null) {
  51. string url = AudioFromFile.Link;
  52. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  53. if (part != null) {
  54. url = part.Uri.ToString().Replace("../", "/ppt/");
  55. HtexBlipFill file = new HtexBlipFill { url = url };
  56. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  57. if (thumbnail != null) {
  58. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  59. //file.contentType = contentType;
  60. }
  61. media.mediaType = "audio";
  62. media.file = file;
  63. }
  64. }
  65. if (VideoFromFile != null) {
  66. string url = VideoFromFile.Link;
  67. var part = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == url).FirstOrDefault();
  68. if (part != null)
  69. {
  70. url = part.Uri.ToString().Replace("../", "/ppt/");
  71. HtexBlipFill file = new HtexBlipFill { url = url };
  72. var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
  73. if (thumbnail != null)
  74. {
  75. var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
  76. // file.contentType = contentType;
  77. }
  78. media.mediaType = "video";
  79. media.file = file;
  80. }
  81. }
  82. SlideColor slideColor = PPTXHelper.DoShapeStyle(image.element.ShapeStyle, slide,type);
  83. //从ShapeProperties 获取 p:spPr
  84. //再从 ShapeStyle 获取 p:spPr
  85. if (ShapeStyle.border == null || ShapeStyle.border.color == null || ShapeStyle.border.color.type == -1)
  86. {
  87. if (slideColor != null)
  88. {
  89. media.style.border.color.solidFill = slideColor.LineColor;
  90. media.style.border.color.type = 2;
  91. }
  92. }
  93. else
  94. {
  95. media.style.border = ShapeStyle.border;
  96. }
  97. if (ShapeStyle.fill == null || ShapeStyle.fill.type == -1)
  98. {
  99. if (slideColor != null)
  100. {
  101. media.style.fill.solidFill = slideColor.FillColor;
  102. media.style.fill.type = 2;
  103. }
  104. }
  105. else
  106. {
  107. media.style.fill = ShapeStyle.fill;
  108. }
  109. HtexBlipFill htexBlipFill = PPTXHelper.DoBlipFill(image.element.BlipFill, slide,partForm);
  110. media.image = htexBlipFill;
  111. media.uid = image.suid;
  112. //TODO 处理公式图片
  113. return new List<Item>() { media };
  114. }
  115. }
  116. }