HtexImage.cs 5.4 KB

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